package com.beagle.njddapp.ui.activity.owner;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.beagle.njddapp.R;
import com.beagle.njddapp.base.BaseMvpActivity;
import com.beagle.njddapp.bean.owner.DIrverOrderBean;
import com.beagle.njddapp.core.UserService;
import com.beagle.njddapp.ui.fragment.CommonMapfragment;
import com.beagle.njddapp.ui.presenter.DirverOrderDetailPresenter;
import com.beagle.njddapp.ui.view.DirverOrderDetailVIew;
import com.beagle.njddapp.utils.StatusBarUtil;
import com.blankj.utilcode.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-21 09:57
 */
public class NjDirverOrderDetailActivity extends BaseMvpActivity<DirverOrderDetailVIew, DirverOrderDetailPresenter> implements DirverOrderDetailVIew {


    @BindView(R.id.commom_title_tv)
    TextView tvTitle;
    @BindView(R.id.common_container)
    RelativeLayout container;
    @BindView(R.id.common_tv_right)
    TextView tvRight;
    private int orderId;
    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_order_type)
    TextView tvType;
    @BindView(R.id.tv_order_number)
    TextView tvOrderNumber;
    @BindView(R.id.tv_order_phone)
    TextView tvPhone;
    @BindView(R.id.tv_order_address)
    TextView tvAddrss;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_order_pay_time)
    TextView payTime;
    @BindView(R.id.tv_order_name)
    TextView tvname;
    @BindView(R.id.tv_yuan)
    TextView tvYuan;
    private DIrverOrderBean dIrverOrderBean;

    @Override
    public int getLayoutId() {
        return R.layout.acrivity_dirver_order_detail;
    }

    @Override
    public void init() {
        StatusBarUtil.immersive(this);
        StatusBarUtil.darkMode(this);
        container.setBackgroundColor(Color.WHITE);
        StatusBarUtil.setPaddingSmart(this, container);
        tvTitle.setText("订单详情");
        dIrverOrderBean = (DIrverOrderBean) getIntent().getSerializableExtra("data");
        addFragment();
        tvNumber.setText(dIrverOrderBean.getMeshNum());
        tvPrice.setText(dIrverOrderBean.getWorkPrice());
        tvType.setText(dIrverOrderBean.getMeshTypeName());
        tvAddrss.setText(dIrverOrderBean.getWorkAddress());
        tvname.setText(dIrverOrderBean.getReceiver());
        tvOrderNumber.setText(dIrverOrderBean.getOrderNum());
        tvPhone.setText(dIrverOrderBean.getReceiverPhone());
        payTime.setText(dIrverOrderBean.getReceiveTime());
        if (5==dIrverOrderBean.getOrderStatus()){
            tvPrice.setTag(dIrverOrderBean.getWorkPrice());

        }else {
            tvPrice.setVisibility(View.GONE);
            tvYuan.setVisibility(View.GONE);
            tvStatus.setVisibility(View.VISIBLE);
        }
        if (0 == dIrverOrderBean.getOrderStatus()) {
            tvStatus.setText("已取消");
            tvStatus.setBackground(getResources().getDrawable(R.drawable.bg_oil_cancle));
        } else if (1 == dIrverOrderBean.getOrderStatus()) {
            tvStatus.setText("待接单");
            tvStatus.setTextColor(Color.parseColor("#E56600"));
            tvStatus.setBackground(getResources().getDrawable(R.drawable.bg_oil_waitting));
        } else if (2 == dIrverOrderBean.getOrderStatus()) {
            tvStatus.setText("处理中");
            tvStatus.setTextColor(Color.parseColor("#E56600"));
            tvStatus.setBackground(getResources().getDrawable(R.drawable.bg_oil_waitting));
        } else if (3 == dIrverOrderBean.getOrderStatus()) {
            tvStatus.setText("待确认");
            tvStatus.setTextColor(Color.parseColor("#E15260"));
            tvStatus.setBackground(getResources().getDrawable(R.drawable.bg_dirver_wait));
        } else if (4 == dIrverOrderBean.getOrderStatus()) {
            tvStatus.setText("处理中");
            tvStatus.setTextColor(Color.parseColor("#E56600"));
            tvStatus.setBackground(getResources().getDrawable(R.drawable.bg_oil_waitting));
        } else if (5 == dIrverOrderBean.getOrderStatus()) {
            tvStatus.setText("归还中");
            tvStatus.setTextColor(Color.parseColor("#49FFFF"));
            tvStatus.setBackground(getResources().getDrawable(R.drawable.bg_oil_finish));
        }else if (6 == dIrverOrderBean.getOrderStatus()) {
            tvStatus.setText("已归还");
            tvStatus.setTextColor(Color.parseColor("#49FFFF"));
            tvStatus.setBackground(getResources().getDrawable(R.drawable.bg_oil_finish));
        }


    }

    private void addFragment() {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        CommonMapfragment commonMapfragment=new CommonMapfragment();
        Bundle bundle=new Bundle();
//        if (dIrverOrderBean.getMeshLocation()!=null){
            bundle.putDouble("latitude",dIrverOrderBean.getMeshLat());
            bundle.putDouble("longitude",dIrverOrderBean.getMeshLng());
//        }
        commonMapfragment.setArguments(bundle);
        transaction.replace(R.id.map_container,commonMapfragment);
        transaction.commitNowAllowingStateLoss();
    }

    @Override
    public DirverOrderDetailVIew getMvpView() {
        return this;
    }

    @Override
    public DirverOrderDetailPresenter createPresenter() {
        return new DirverOrderDetailPresenter();
    }

    @Override
    public void onError(String message) {
        ToastUtils.showShort(message);
    }


    @OnClick({R.id.common_tv_right, R.id.common_back_iv})
    public void onMyClick(View view) {
        switch (view.getId()) {
            case R.id.common_back_iv:
                onBackPressed();
                break;
            case R.id.common_tv_right:

                break;

        }
    }
}
